// pages/login/login.js
var app = getApp();
Page({
    data: {
        telephone:'',
        password: '',
        title:'绑定账号',
        bak:0  //用户是登录用户不是绑定用户
      
    },

    onLoad: function (options){
      console.log(options.login)
      if (options.login){
            this.setData({
                title:'登录',
                bak:1
            })
        }
    },
    getTel: function (e) {
        this.setData({
            telephone: e.detail.value
        })
    },
    getpassword: function (e) {
        this.setData({
            password: e.detail.value
        })
    },

    bconfirm:function(){
        if(this.data.jb){
            this.jBind();
        }else{
            this.login();
        }
    },
   
    login: function () {
        var that = this;
        wx.request({
            url: app.globalData.api + "bindAgent",
            data: {
                phone: that.data.telephone,
                password: that.data.password,
                appOpenid: wx.getStorageSync('kyboppenid'),
                bak: that.data.bak
            },
            success: function (res) {

                if (res.data.code == 500) {
                    wx.showToast({
                        title: res.data.msg,
                        icon: 'none'
                    })
                } else if (res.data.code == 0) {
                    wx.setStorageSync('userDo', res.data.userDO)
                    wx.setStorageSync('noBind', false)
                    var sTitle = "绑定成功！"
                    if (that.data.bak){
                      wx.setStorageSync('isLogin', true);
                      sTitle = "登录成功！"
                      
                    }
                    wx.showToast({
                      title: sTitle

                    })
                   
                    setTimeout(function () {
                        wx.switchTab({
                            url: '/pages/home/home',
                        })
                    }, 1000)
                }
            }

        })
    },

 
})